/*
 * PermissionsPanel.java
 *
 * Created on April 25, 2007, 11:18 AM
 */

package org.glossitope.container.ui;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.JDialog;
import javax.swing.JLabel;

/**
 *
 * @author  joshy
 */
public class PermissionsPanel extends javax.swing.JPanel {
    private JDialog dialog;
    private GridBagConstraints gbc, sg;
    private JLabel spacer;
    
    /** Creates new form PermissionsPanel
     * @param dialog
     */
    public PermissionsPanel(JDialog dialog) {
        this();
        this.dialog = dialog;
    }
    public PermissionsPanel() {
        initComponents();
        gbc = new GridBagConstraints();
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbc.weightx = 0.0;
        gbc.weighty = 0.0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.anchor = GridBagConstraints.NORTHWEST;
        
        spacer = new JLabel("spacer");
        sg = new GridBagConstraints();
        GridBagLayout gbl = (GridBagLayout) innerPanel.getLayout();
        sg.gridwidth = GridBagConstraints.REMAINDER;
        sg.fill = GridBagConstraints.HORIZONTAL;
        sg.anchor = GridBagConstraints.NORTHWEST;
        sg.weightx = 1.0;
        sg.weighty = 1.0;
        gbl.setConstraints(spacer, sg);
        innerPanel.add(spacer);
    }
    
    public void addGrant(GrantPanel panel) {
        innerPanel.remove(spacer);
        GridBagLayout gbl = (GridBagLayout) innerPanel.getLayout();
        gbl.setConstraints(panel, gbc);
        innerPanel.add(panel);
        gbl.setConstraints(spacer, sg);
        innerPanel.add(spacer);
        innerPanel.validate();
        innerPanel.repaint();
    }
    public void removeGrant(GrantPanel panel) {
        innerPanel.remove(panel);
        innerPanel.validate();
        innerPanel.repaint();
        if(innerPanel.getComponentCount() <= 1) {
            this.dialog.setVisible(false);
        }
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        innerPanel = new javax.swing.JPanel();

        jButton1.setText("Close");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel1.setText("Permissions Request");

        innerPanel.setLayout(new java.awt.GridBagLayout());
        jScrollPane1.setViewportView(innerPanel);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel1)
                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 203, Short.MAX_VALUE)
                .add(53, 53, 53))
        );
    }// </editor-fold>//GEN-END:initComponents
    
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    this.dialog.setVisible(false);
}//GEN-LAST:event_jButton1ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel innerPanel;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
    
}
